package ar.edu.uba.fi.jmit.graphvisualizer.receiver;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import ar.edu.uba.fi.jmit.receiver.Receiver;
import ar.edu.uba.fi.jmit.receiver.ReceiverFactory;

public class GraphVisualizerServlet extends HttpServlet {
	
	private static final long serialVersionUID = 7375438803320515907L;
	private Logger logger;
	
	public GraphVisualizerServlet() {
		super();
		this.logger = Logger.getLogger(this.getClass());
	}
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		logger.info("Initializing GraphVisualizer");
		Receiver receiver = ReceiverFactory.getInstance().getReceiver("receiver");
		addObservers(receiver);
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		logger.info("at doGet");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		logger.info("at doPost");
	}
	
	protected void addObservers(Receiver receiver) {
		logger.info("Adding Graph Visualizer");
		receiver.addObserver(ReceiverObserverImpl.getInstance());
		receiver.addObserver(DynamicMenuObserverImpl.getInstance());
		receiver.addObserver(SecondaryInformationObserverImpl.getInstance());
	}
}
